<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>在类中使用访问器</title>
  </head>
  <body></body>
  <script>
    class Request {
      constructor(host) {
        this.data = {};
        this.data.host = host;
      }
      set host(url) {
        if (!/^https?:\/\//i.test(url)) {
          throw new Error("地址错误");
        }
        this.data.host = url;
      }
      get host() {
        return this.data["host"];
      }
    }
    let hd = new Request("https://www.houdunren.com");

    hd.host = "https://www.baidu.com";
    console.log(hd.host);
    console.log(hd);
  </script>
</html>
